package com.zl.petstore.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyFrame extends JFrame {

    //获得屏幕宽度
    private double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth();

    //获得屏幕高度
    private double screenHeigth = Toolkit.getDefaultToolkit().getScreenSize().getHeight();

    public MyFrame(String title, int width, int heigth) {
        super(title);

        //设置窗口大小
        setSize(width, heigth);
        //计算窗口居中坐标
        int x = (int)(screenWidth - width) / 2;
        int y = (int)(screenHeigth - heigth) / 2;
        //设置窗口位置
        setLocation(x,y);

        //注册窗口事件
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // TODO Auto-generated method stub
//				super.windowClosing(e);
                //退出系统
                System.exit(0);
            }

        });
    }

}
